using System;
using System.ComponentModel;
using BpNTClass;
using BpNTClass.DebugOutput;

namespace BpNTClassInternal
{

    internal class BpNTPropertyDescriptor : PropertyDescriptor
    {
        int _Index;
        string _DisplayName;
        Type _TypeOf;
        public BpNTPropertyDescriptor(int index, string displayName, Type typeOf)
            : base(displayName, null)
        {
            _Index = index;
            _DisplayName = displayName;
            _TypeOf = typeOf;
        }
        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override Type ComponentType
        {
            get
            {
#if DEBUG
                writeln.Prog(" !#!#! GET ComponentType " + typeof(DataObject).ToString());
#endif
                return typeof(DataObject);
            }
        }

        public override string DisplayName
        {
            get
            {
#if DEBUG
                writeln.Prog(" !#!#! DisplayName " + _DisplayName);
#endif
                return _DisplayName;
            }
        }

        public override object GetValue(object component)
        {
#if DEBUG
            writeln.Prog(" !#!#! GetValue " + ((DataObject)component)[_Index]);
#endif
            return ((DataObject)component)[_Index];
        }

        public override bool IsReadOnly
        {
            get { return true; }
        }

        public override Type PropertyType
        {
            get
            {
#if DEBUG
                writeln.Prog(" !#!#! PropertyType " + _TypeOf.ToString());
#endif
                return _TypeOf;
            }
        }

        public override void ResetValue(object component)
        {
#if DEBUG
            writeln.Prog(" !#!#! ResetValue" + component.ToString());
#endif
        }

        public override void SetValue(object component, object value)
        {
#if DEBUG
            writeln.Prog(" !#!#! SetValue" + component.ToString() + " ## " + value.ToString());
#endif
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }
    }
}
